'''回溯算法 全排列2'''
def fun(nums):
    used=[False]*len(nums)
    path=[]
    result=[]
    def backtracking(nums,used):
        if len(path)==len(nums):
            result.append(path[:])
            return
        for i in range(len(nums)):
            if not used[i]:
                if nums[i]==nums[i-1] and i>0 and not used[i-1]:
                    continue
                used[i]=True
                path.append(nums[i])
                backtracking(nums,used)
                used[i]=False
                path.pop()
    backtracking(sorted(nums),used)
    return result
res=fun([1,1,2])
print(res)
